package com.mhwx.mhlive.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.mhwx.mhlive.R;
import com.mhwx.mhlive.model.UserContent;
import com.mhwx.mhlive.presenter.SearchPresenter;
import com.mhwx.mhlive.ui.adapter.SearchAdapter;
import com.mhwx.mhlive.ui.base.BaseActivity;
import com.mhwx.mhlive.view.SearchView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

/**
 * 类功能描述
 * 搜索
 * @author Guol
 * @version 1.0
 * @copyright 北京明华维新信息技术有限公司
 * @time 2017/4/26
 */
public class SearchActivity  extends BaseActivity implements SearchView {

    @BindView(R.id.recycler)
    RecyclerView recycler;

    @BindView(R.id.rotate_header_grid_view_frame)
    PtrClassicFrameLayout mPtrFrame;
    private List<String> mDatas;
    private SearchAdapter mAdapter;
    private SearchPresenter presenter;
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_search);
        init();
    }

    private  void  init(){
        recycler.setLayoutManager(new LinearLayoutManager(this));
        presenter=new SearchPresenter(this,this);
        presenter.getDate();

        mPtrFrame.setLastUpdateTimeRelateObject(this);
        mPtrFrame.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
//                updateData();
                mPtrFrame.refreshComplete();
                presenter.getDate();
            }

        });
    }

    protected void initData()
    {
        mDatas = new ArrayList<String>();
        UserContent bean;
        for (int i = 'A'; i < 'z'; i++)
        {
            mDatas.add("" + (char) i);
        }
       if (mAdapter==null)
        mAdapter=new SearchAdapter(mDatas);
        recycler.setAdapter(mAdapter);

    }

    @Override
    public void getDate() {
        initData();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void closeLoading() {

    }
}
